package com.example.client;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author 时鸣雨
 * @target
 */
public class Client {
    public static String GET(String url_){
        String result = "";
        BufferedReader inData = null;
        try{
            URL url = new URL(url_);
            URLConnection urlConnection = url.openConnection();
            urlConnection.setRequestProperty("accept" , "*/*");
            urlConnection.setRequestProperty("connection" , "keep-alive");
            urlConnection.setRequestProperty("user-agent" , "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46");
            urlConnection.connect();
            InputStreamReader inputStreamReader = new InputStreamReader(urlConnection.getInputStream());
            inData = new BufferedReader(inputStreamReader);
            String lineData = "";
            while ((lineData = inData.readLine()) != null){
                result += lineData;
            }
        }catch (Exception e){
            System.out.println("GET操作异常"+e.getMessage());
        }finally {
            try{
                if(inData != null){
                    inData.close();
                }
            }catch (Exception e){
                System.out.println("IO异常"+e.getMessage());
            }
        }
        return result;
    }

}
